package com.huluobo.a2308douyindemo.live

import com.huluobo.a2308douyindemo.bean.DanmakuBean
import com.huluobo.a2308douyindemo.bean.GIftBean
import com.huluobo.a2308douyindemo.bean.Gift7037Bean
import com.huluobo.a2308douyindemo.bean.GoodsBean
import com.huluobo.a2308douyindemo.mvvm.BaseViewModel
import com.huluobo.a2308douyindemo.net.ApiService
import com.huluobo.a2308douyindemo.net.ApiServiceGift
import com.huluobo.a2308douyindemo.net.Res
import com.huluobo.a2308douyindemo.utils.UnPeekLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

/**
 *  Created by LC on 2025/10/29.
 */
@HiltViewModel
class LiveViewModel @Inject constructor(
    private val apiService: ApiService,
    private val giftApiService: ApiServiceGift
) : BaseViewModel() {
    val focusedSuccess by lazy { UnPeekLiveData<Res<Boolean>>() }
    fun focusedUser(userId: Int, authId: String) {
        executeNetwork(
            { apiService.focusUser(userId, authId) },
            focusedSuccess::setContentValue
        )
    }

    val unFocusSuccess by lazy { UnPeekLiveData<Res<Boolean>>() }
    fun unFocusUser(userId: Int, authId: String) {
        executeNetwork(
            {
                apiService.unFocsUser(userId, authId)
            },
            unFocusSuccess::setContentValue
        )
    }

    val sendDanmakuSuccess by lazy { UnPeekLiveData<Res<DanmakuBean>>() }
    fun sendDanmaku(danmakuBean: DanmakuBean) {
        executeNetwork(
            { apiService.sendDanmaku(objToJson(danmakuBean)) },
            sendDanmakuSuccess::setContentValue
        )
    }

    val getDanmakuSuccess by lazy { UnPeekLiveData<Res<List<DanmakuBean>>>() }
    fun getDanmaku(dataType: Int, itemId: String) {
        executeNetwork(
            { apiService.getDanmaku(dataType, itemId) },
            getDanmakuSuccess::setContentValue
        )
    }


    //请求7012礼物地址
    val getGiftSuccess by lazy { UnPeekLiveData<Res<List<GIftBean>>>() }
    fun getGift() {
        executeNetwork(
            { giftApiService.getGift() },
            getGiftSuccess::setContentValue
        )
    }

    //请求7037礼物地址
    val getGift7037Success by lazy { UnPeekLiveData<Res<List<Gift7037Bean>>>() }
    fun getGift7037() {
        executeNetwork(
            { apiService.getGift() },
            getGift7037Success::setContentValue
        )
    }

    //修改金币余额
    val modifyCoinSuccess by lazy { UnPeekLiveData<Res<Boolean>>() }
    fun modifyCoin(id: Int, um: String) {
        executeNetwork(
            { apiService.modifyCoin(id, um) },
            modifyCoinSuccess::setContentValue
        )
    }

    //修改余额
    val modifyAccountSuccess by lazy { UnPeekLiveData<Res<Boolean>>() }
    fun modifyAccount(id: Int, um: String) {
        executeNetwork(
            { apiService.modifyAccount(id, um) },
            modifyAccountSuccess::setContentValue
        )
    }

    val getGoodsInfoSuccess by lazy { UnPeekLiveData<Res<List<GoodsBean>>>() }
    fun getGoodsInfo(categoryId: Int, currentPage: Int, pageSize: Int) {
        executeNetwork(
            { giftApiService.getGoodsInfo(categoryId, currentPage, pageSize) },
            getGoodsInfoSuccess::setContentValue
        )
    }

}